home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BMP2BGI1.ZIP / SHOWBGI2.C < prev    next >
C/C++ Source or Header  |  1991-05-25  |  3KB  |  63 lines

  1. #include <stdio.h>
  2. #include <graphics.h>
  3. #include <alloc.h>
  4. #include "bgi.h"
  5.  
  6. extern BGIPREFACE BGIHeader;                    // Header stuff for the BGI
  7.                                                 // files created w/ BMP2BGI
  8.  
  9. void ShowBGI (FILE *f, char far *VidBuf[5])
  10. {
  11.   int ystart=0, yend, yincr, i;                 // var's for processing BGI images >= 64k
  12.   unsigned size;
  13.                                                 
  14.   setallpalette(&BGIHeader.palette);            // Set the screen palette
  15.  
  16.                                                 // Just how big are we talking?
  17.   size = imagesize(0, 0, BGIHeader.Width, BGIHeader.Height);
  18.  
  19.  
  20.                                                 // Reset File pointer to where
  21.                                                 // the image resides
  22.   fseek(f, BGIHeader.Foffset, SEEK_SET);
  23.  
  24.                                                 // if image is less than 64k-1
  25.                                                 // bytes, read it all in at once
  26.   if (size != NULLIMAGESIZE)
  27.   {
  28.                                                 // Alloc space for image
  29.         VidBuf[0] = (char far *) farmalloc((unsigned long) size);
  30.                                                 // Read in image     
  31.         fread(VidBuf[0], sizeof(char), size, f);
  32.         putimage(0, 0, VidBuf[0], COPY_PUT);    // & Display the image
  33.         farfree(VidBuf[0]);                     // Free up allocated space
  34.   }
  35.   else                                          // if image is >= 64k, gotta 
  36.   {                                             // fetch & display in chunks
  37.         yincr = (BGIHeader.Height+1) / 5;       // large images are stored in fifths
  38.         yend = yincr;                           // track end of chunk
  39.         size = imagesize(0,ystart,BGIHeader.Width,yend);
  40.              
  41.         for (i=0; i < 5; i++)
  42.         {
  43.                 if ((VidBuf[i] = (char far *) farmalloc((unsigned long) size)) == NULL)
  44.                 {
  45.                                                 // Can't display: No memory for image
  46.                         closegraph();
  47.                         printf("ShowBGI> Out of heap space.\n");
  48.                         printf("ShowBGI> Press any key to abort");
  49.                         getch();
  50.                         exit(12);
  51.                 }
  52.                                                 // Read in i-th chunk
  53.                 fread(VidBuf[i], sizeof(char), size, f);
  54.                                                 // and display the chunk
  55.                 putimage(0, ystart, VidBuf[i], COPY_PUT);
  56.                 farfree(VidBuf[i]);             // free up some memory
  57.                 ystart = yend + 1;              // advance boundaries for
  58.                 yend += yincr + 1;              // next chunk   
  59.         }
  60.  
  61.  
  62.   }
  63. }